package com.ruoyi.system.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ruoyi.common.core.domain.entity.SysMenu;

import java.util.List;

@Repository
public interface SysMenuDAO extends JpaRepository<SysMenu, String>, JpaSpecificationExecutor<SysMenu> {
	
	
	public SysMenu findTop1ByMenuNameAndParentId(String menuName,String parentId);

	@Query(value = "SELECT DISTINCT m.perms  FROM sys_menu m " +
			" LEFT JOIN sys_post_menu pm ON m.menu_id = pm.menu_id " +
			" LEFT JOIN sys_role_post rp ON rp.post_id = pm.post_id " +
			" LEFT JOIN sys_role_user ru ON ru.role_id = rp.role_id " +
			" LEFT JOIN sys_role r on r.role_id = rp.role_id " +
			"WHERE " +
			" m.STATUS = '0' AND r.STATUS = '0' and ifnull(m.perms,'') <> '' " +
			" and ru.user_id = ?1", nativeQuery = true)
	public List<String> selectMenuPermsByUserId(String userId);
}
